JavaScript Records & Tuples Proposal
https://github.com/tc39/proposal-record-tuple
2023/5/30現在stage 2
playground
immutableなtupleとrecordを定義できる
以下のようなsyntax
code:ts
const ship1 = #{ x: 1, y: 2 };
const tuple = #1, 2, 3;
値の透過性比較ができる
code:ts
assert(#{ a: 1 } === #{ a: 1 }); // ok
assert(#1 === #1); // ok
これ入ったら別言語じゃん、すごいmrsekut.icon
immutableなので変更しようとするとerror
code:js
const record = #{ prop: 1 };
record.prop = 2 // "Cannot assign to read only property 'prop' of object 'object Object'"
record-tuple-polyfill
https://github.com/bloomberg/record-tuple-polyfill
https://www.wantedly.com/companies/wantedly/post_articles/511889
polyfillをどういう風に実装しているのかの解説
Interning
同等の値を持つオブジェクトは1つしか作られないようにするというもの
#ECMAScript_Proposal